import 'package:flutter/material.dart';

class ListExpand extends StatefulWidget {
  const ListExpand({
    super.key,
    required this.onExpand,
    required this.onSystole,
    this.expandSize = 50.0,
    this.systoleSize = 30.0,
    required this.child,
  });

  final Widget child;
  final VoidCallback onExpand;
  final VoidCallback onSystole;
  final double expandSize;
  final double systoleSize;

  @override
  _ListExpandState createState() => _ListExpandState();
}

class _ListExpandState extends State<ListExpand> {
//手指移动的位置
//   double _lastMoveY = 0.0;

  //手指按下的位置
  double _downY = 0.0;

  @override
  Widget build(BuildContext context) {
    return Listener(
        onPointerDown: (PointerDownEvent event) {
          //手指按下的距离
          _downY = event.position.dy;
        },
        onPointerMove: (PointerMoveEvent event) {
          // logs(event.position.dy);
          //手指移动的距离
          var positionY = event.position.dy;
          // //判断距离差
          var detal = (positionY - _downY) / 4;
          // // logs(detal);
          if (detal > widget.expandSize) {
            widget.onExpand();
          } else if (detal < -widget.systoleSize) {
            widget.onSystole();
          }
        },
        child: widget.child);
  }
}
